package com.study.servlet;

import com.study.utils.ZXingCodeDecodeUtils;
import com.study.utils.ZXingCodeEncodeUtils;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

/**
 * 生成二维码的Servlet
 * @author Deja wu
 */

@WebServlet("/decode")
@MultipartConfig
public class DeCodeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Part part = req.getPart("mf");
        String s = ZXingCodeDecodeUtils.decodeCodeStream(part.getInputStream());
        PrintWriter writer = resp.getWriter();
        writer.write(s);
        writer.flush();
        writer.close();
    }
}
